import socket
import threading
class chat_client():
    def __init__(self,host,port):
        #初始化socket对象
        self.host=host
        self.port=port
        self.client=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    #运行
    def run(self):
        self.client.connect((self.host,self.port))
        threading.Thread(target=self.get_msg).start()
        threading.Thread(target=self.send_msg).start()
    #发送消息
    def send_msg(self):
        while True:
            msg=input()
            self.client.send(msg.encode('utf-8'))
    #接收消息
    def get_msg(self):
        while True:
            msg=self.client.recv(1024)
            print(msg.decode())


def main():
    host='192.168.0.98'
    port=9999
    cc=chat_client(host,port)
    cc.run()
if __name__=='__main__':
    main()